//引入
import { request } from "../utils/request.js";

//获取推荐歌单
async function getReMusic(){
   let res = await request("/personalized").then(res => res)
   return res.data.result
}

//根据传入的id获取点击歌单的详细信息
async function getPlayMusic(musicId){
   let res = await request(`/playlist/detail?id=${musicId}`).then(res => res)
   return res.data.playlist
}

//根据传入的id获得评论(默认limit为20个)
async function getComment(musicId){
   let res = await request(`/comment/playlist?id=${musicId}&limit=100`).then(res => res)
   return res.data
}

//获取最新音乐
async function getNewMusic(){
   let res = await request("personalized/newsong").then(res => res)
   return res.data.result
}

//获取轮播图(iphone端)
async function getBanner(){
   let res = await request("banner?type=2").then(res => res)
   return res.data.banners
}

//获取榜单音乐(热歌榜,电音榜,飙升榜,原创歌曲榜)
async function getHotMusic(){
   let res = await request("/top/list?idx=1").then(res => res)
   return res.data.playlist
}
async function getHiMusic(){
   let res = await request("/top/list?idx=0").then(res => res)
   return res.data.playlist
}
async function getSurgeMusic(){
   let res = await request("/top/list?idx=3").then(res => res)
   return res.data.playlist
}
async function getOriginalMusic(){
   let res = await request("/top/list?idx=2").then(res => res)
   return res.data.playlist
}

//获取热门歌曲
async function getHongSong() {
   let res = await request("/search/hot").then(function (res) { return res });
   return res.data.result.hots;
}
//获取搜索歌曲
async function getSearchSong(key){
   let res = await request(`/search?keywords=${key}`).then(function (res) { return res });
   if(res.data.result.songCount== 0 )
       return [];
   else
   return res.data.result.songs;
}

async function getLyric(id){
   let res = await request(`lyric?id=${id}`).then(function (res) { return res });
   // console.log(res.data);
 
   if('lrc' in res.data)
   {         
      return res.data.lrc.lyric;
   }
     
   else{      
      return ""
   }
  
   
}
//输出 函数
export { getReMusic,getBanner,getPlayMusic,getComment,getHotMusic,getHiMusic,getSurgeMusic,getOriginalMusic,getNewMusic,getHongSong,getSearchSong ,getLyric}

